<template>
  <div class="container">
    <!-- 2. 搜索区域 -->
    <div class="header">
      <el-input v-model="input" @change="searchInput" placeholder="请输入内容"></el-input>
      <el-button type="primary">查询</el-button>
      <router-link to="./add-orders">
        <el-button type="primary">添加</el-button>
      </router-link>
    </div>
    <!-- 3. 表格 -->
    <div class="order-list">
      <el-table :data="tableData" border :header-cell-style="{ 'text-align': 'center' }">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column prop="id" label="ID" width="80"></el-table-column>
        <el-table-column prop="title" label="商品名称" width="110" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="num" label="购买数量" width="90"> </el-table-column>
        <el-table-column prop="user.name" label="购买人" width="110"> </el-table-column>
        <el-table-column prop="address" label="收货地址" show-overflow-tooltip> </el-table-column>
        <el-table-column prop="time" label="购买日期"> </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-edit"
              @click="handleEdit(scope.$index, scope.row)"
              >编辑</el-button
            >
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
              icon="el-icon-delete"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>

    <!-- 4. 分页 -->
    <MyPagination :total="total" :pageSize="1" @changePage="changePage" />
  </div>
</template>

<script>
import MyPagination from '../../components/MyPagination.vue'
export default {
  components: {
    MyPagination
  },
  data() {
    return {
      input: '',
      formInline: {
        user: '',
        region: ''
      },
      tableData: [],
      total: 1,
      pageSize: 1
    }
  },
  methods: {
    searchInput() {},

    change() {},

    changePage(num) {
      this.http(num)
    },

    handleEdit() {},

    handleDelete() {},

    http(currPage) {
      this.$api.orderList({ currPage }).then((res) => {
        if (res.data.status === 200) {
          this.tableData = res.data.data.list
          this.total = res.data.data.totalPage
        } else {
          this.tableData = []
          this.total = 1
        }
      })
    }
  },
  created() {
    this.http(1)
  }
}
</script>

<style lang="less" scoped>
.container {
  margin: 10px;
}
.nav {
  padding: 10px;
}
.header {
  display: flex;
  background: #fff;
  padding: 10px;
  border: 1px solid #eee;
  button {
    margin-left: 20px;
  }
  .el-form-item {
    margin-bottom: 0;
  }
}
// 订单列表
.order-list {
  margin: 20px 0;
  padding: 16px;
  border: 1px solid #eee;
  background: #fff;
}
</style>
